﻿using System;
using System.Data;
using System.ServiceModel;
using Cinchoo.Core.Xml.Serialization;
using System.Runtime.Serialization;
using System.Collections.Generic;
using Cinchoo.IO;

namespace ChoWorkflowServer.Model
{
    [ServiceContract]
    public interface IChoDataModel : IDisposable
    {
        [OperationContract]
        Version GetVersion();
        [OperationContract]
        int GetTaskId(string taskName);
        [OperationContract]
        bool IsTaskExists(string taskName);
        [OperationContract]
        int AddOrUpdateTask(string taskName, string workflowName, string taskDesc, int taskGroupId, string cmdParameters,
            int? maxNoOfRetry, int? sleepBetweenRetry, int? timeout, string hostName,
            ChoTasksDataSet.CHO_TASK_SCHEDULESDataTable taskScheduleInfo, string modifiedBy, string modifiedByHostName);
        [OperationContract]
        int CloneTask(string taskName, string newTaskName, string taskGroupName, string newTaskGroupNam, string modifiedBy, string machineName);
        [OperationContract]
        void DeleteTask(string taskName, string modifiedBy, string machineName);
        [OperationContract]
        ChoTasksDataSet.CHO_TASK_GRPSDataTable GetAllTaskGroups();
        [OperationContract]
        ChoTasksDataSet.CHO_TASKSDataTable GetAllUITasks(string taskName, string taskGrpName);
        [OperationContract]
        ChoTasksDataSet.CHO_TASKSDataTable GetAllTasks(string taskName, string taskGrpName, string machineName, DateTime modifiedDate);

        [OperationContract]
        void SetTaskStatus(int batchId, string taskName, string scheduleName, Cinchoo.Core.ETL.ChoETLWorkflowStatus taskStatus, string modifiedBy, string modifiedByHostName, string logMsg = null, string nextRunTime = null, string machineNamae = null);
        [OperationContract]
        Cinchoo.Core.ETL.ChoETLWorkflowStatus GetTaskStatus(string taskName, string scheduleName);
        [OperationContract]
        int GetTaskExitCode(string taskName, string scheduleName);
        [OperationContract]
        void AddOrUpdateTaskBatch(int batchId, string taskName, string scheduleName, int taskStatus, string cmdParameters, string machineName, string logMsg, DateTime processStart,
            DateTime? processEnd, TimeSpan? duration, string nextRunTime, int exitCode, int? retryCount, string modifiedBy, string modifiedByHostName);

        [OperationContract]
        int AddOrUpdateTaskGroup(string taskGroupName, string taskGroupDesc, int parent, string modifiedBy, string machineName);
        [OperationContract]
        void DeleteTaskGroup(string taskGroupName, string modifiedBy, string machineName);
        [OperationContract]
        bool IsTaskGroupExists(string taskGroupName);
        [OperationContract]
        void MoveTask(string taskName, int srcTaskGrpId, int destTaskGrpId, string modifiedBy, string machineName);
        [OperationContract]
        void ImportTasks(ChoTasksDataSet tasksTable, string modifiedBy, string machineName);

        [OperationContract]
        ChoTasksDataSet.CHO_HOLIDAY_CALENDARSDataTable GetAllHolidayCalendars();
        [OperationContract]
        void UpdateHolidayCalendar(ChoTasksDataSet.CHO_HOLIDAY_CALENDARSDataTable calendarTable,
            ChoTasksDataSet.CHO_HOLIDAY_CALENDAR_DATESDataTable calendarDatesTable, string modifiedBy, string machineName);
        [OperationContract]
        ChoTasksDataSet.CHO_HOLIDAY_CALENDAR_DATESDataTable GetAllHolidayCalendarDatesById(int holidayCalId);
        [OperationContract]
        ChoTasksDataSet.CHO_HOLIDAY_CALENDAR_DATESDataTable GetAllHolidayCalendarDatesByName(string holidayCalName);
        [OperationContract]
        int CloneCalendar(string calName, string newCalName, string modifiedBy, string machineName);

        [OperationContract]
        ChoTasksDataSet.CHO_TASK_SCHEDULESDataTable GetTaskSchedules(int taskId, string scheduleName);
        [OperationContract]
        ChoTasksDataSet.CHO_SCHEDULE_TYPESDataTable GetTaskScheduleTypes();

        [OperationContract]
        bool IsUserPolicyEnabled();

        [OperationContract]
        ChoTasksDataSet.CHO_POLICYDataTable GetAllPolicy();
        [OperationContract]
        ChoTasksDataSet.CHO_USERSDataTable GetAllUsers();
        [OperationContract]
        void UpdateUsers(ChoTasksDataSet.CHO_USERSDataTable usersTable, string modifiedBy, string machineName);

        [OperationContract]
        ChoTasksDataSet.CHO_ROLESDataTable GetAllRoles();
        [OperationContract]
        ChoTasksDataSet.CHO_ROLE_USERSDataTable GetAllUserRoles(int roleId);
        [OperationContract]
        ChoTasksDataSet.CHO_ROLE_POLICYDataTable GetAllRolePolicy(int roleId);
        [OperationContract]
        void UpdateRoles(ChoTasksDataSet.CHO_ROLESDataTable rolesTable, ChoTasksDataSet.CHO_ROLE_USERSDataTable userRolesTable,
            ChoTasksDataSet.CHO_ROLE_POLICYDataTable rolesPolicyTable, string modifiedBy, string machineName);
        [OperationContract]
        ChoTasksDataSet.CHO_POLICYDataTable GetPolicyForUser(string userName);

        [OperationContract]
        ChoTasksDataSet.CHO_DEPENDENCY_TASKSDataTable GetAllDepedencyTasks(string jobName);

        [OperationContract]
        byte[] DownloadWFPlugIn(string wfPlugInRelativeFilePath);
        [OperationContract]
        ChoFSFileInfo[] GetWFPlugInsFileList();

        [OperationContract]
        byte[] DownloadWFDef(string wfDefRelativeFilePath);
        [OperationContract]
        ChoFSFileInfo[] GetWFDefsFileList();

        [OperationContract]
        byte[] DownloadWFData(string wfDataRelativeFilePath);
        [OperationContract]
        ChoFSFileInfo[] GetWFDataFileList();

        [OperationContract]
        KeyValuePair<string, string>[] GetClusterNodePairs();

        [OperationContract]
        void FireDependentTasks(int batchId, string taskName, string scheduleName, string user, string originHostName);

        [OperationContract]
        void RefreshDB();

        IChoWorkflowScheduler WorkflowScheduler
        {
            get;
            set;
        }
    }
}
